package com.horoscope.astrology.zodiac.signs.free.utils

import android.content.Context
import android.view.View
import android.widget.Toast
import com.horoscope.astrology.zodiac.signs.free.R

object ToastUtil {

    var lastTime = 0L
    var mToast: Toast? = null
    val view: View? = null

    fun showRewardError(context: Context) {
        cancel()
        val currentTime = System.currentTimeMillis()
        if (currentTime - lastTime > 2800) {
            if (mToast == null) {
                mToast = Toast.makeText(
                    context,
                    R.string.tips_reward_video_failed_to_load,
                    Toast.LENGTH_SHORT
                )
            }
            lastTime = currentTime
            mToast!!.show()
        }
    }

    fun showText(context: Context, string: String) {
        cancel()
        val currentTime = System.currentTimeMillis()
        if (currentTime - lastTime > 2800) {
            if (mToast == null) {
                mToast = Toast.makeText(context, string, Toast.LENGTH_SHORT)
            }
            lastTime = currentTime
            mToast!!.show()
        }
    }

    /**
     * toast取消
     */
    fun cancel() {
        if (mToast != null) {
            mToast!!.cancel()
            mToast = null
        }
    }
}